<?php
class MemberComponent extends Object{
	var $components = array( 'Auth','Session','RequestHandler');
	
	public function initialize(&$controller) {
        $this->controller = $controller;
        $this->data = $controller->data;  	
    }
	
	public function get_all(){
		$model =& $this->getModel('Member');
	    if(!$model){
	      return false;
	    }
	    $member_schema = $model->schema();
	    $fields = array('MemberUpload.name');
		if(is_array($member_schema)){
	    	foreach ($member_schema as $column => $value) {
	    		array_push($fields,"Member.{$column}");
	    	}
	    }else{
	    	$fields = array('Member.id','Member.name','Member.full_name','Member.lp');
	    }
	    $model->recursive = -1;
	    
	    $joins = array( array('table' => 'member_uploads', 'alias' => 'MemberUpload', 'type' => 'LEFT', 'conditions' => array( 'MemberUpload.id = Member.upload_id')));
	    $items = $model->find('all',array('fields'=>$fields,'joins'=>$joins,'order'=>array('Member.country')));
	    return $items;
	}
	
	function &getModel($name = null) {
		$model = null;
		if (!$name) {
			$name = 'Member';
		}    
		if($name){
			if (PHP5) {
				$model = ClassRegistry::init($name);
			} else {
				$model =& ClassRegistry::init($name);
			}

			if (empty($model)) {
//				$this->_error('FileUpload::getModel() - Model is not set or could not be found');
				return null;
			}
		}
		return $model;
	}
}